const int N = 1e5 + 10;
int st[N], st2[N];
class Solution {
public:
    vector<vector<int>> findWinners(vector<vector<int>>& matches) {
        memset(st, 0, sizeof(st));
        memset(st2, 0, sizeof(st2));
        for (auto x : matches) {
            int a = x[0];
            int b = x[1];
            st[b]++;
            st2[a] = 1, st2[b] = 1;
        }
        vector<int>ans1, ans2;
        for (int i = 1; i <= 1e5; i++) {
            if (!st2[i])continue;
            if (!st[i])ans1.push_back(i);
            else if (st[i] == 1)ans2.push_back(i);
        }
        sort(ans1.begin(), ans1.end());
        sort(ans2.begin(), ans2.end());
        vector<vector<int>>res;
        res.push_back(ans1);
        res.push_back(ans2);
        return res;
    }
};